package com.example.designpattenexample.mixpatten.example1;

public class SteadyDeduction implements IDeduction {

    @Override
    public boolean exec(ICard card, Trade trade) {
        boolean tradeFlag = false;
        double steadyMoney = card.getSteadyMoney();
        double freeMoney = card.getFreeMoney();
        double cardTotalMoney = steadyMoney + freeMoney;
        double tradeAmount = trade.getAmount();
        if (cardTotalMoney >= tradeAmount) {
            tradeFlag = true;
            card.setSteadyMoney(steadyMoney > tradeAmount ? (steadyMoney - tradeAmount) : 0);
            card.setFreeMoney( steadyMoney > tradeAmount ? freeMoney : cardTotalMoney - tradeAmount);
        }
        return tradeFlag;
    }
}
